home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / AIAT 1.0.1 / Headers / Storage / IAStoreStream.h < prev    next >
Encoding:
Text File  |  1997-09-11  |  3.4 KB  |  109 lines  |  [TEXT/CWIE]

  1. // IAStoreStream.h
  2. //    Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4.  
  5. // for implementing IAStorage on different file systems
  6. // implementations need only implement pure virtual members
  7. // clients should not use this directly, but rather use through an IAStorage
  8.  
  9. #pragma once
  10. #ifndef IAStoreStream_h
  11. #define IAStoreStream_h
  12.  
  13. #pragma import on
  14.  
  15. #include "IACommon.h"
  16. #include "IAMutex.h"
  17.  
  18. #pragma IA_BEGIN_EXPORTS
  19.  
  20. class IAStoreStream : public IAObject {
  21.     friend class    IAOutputBlock;
  22.     friend class    IAInputBlock;
  23.     friend class    IAStorage;
  24. public:
  25.                     IAStoreStream();
  26.     virtual            ~IAStoreStream();
  27.     // Returns a new storeStream read/writing the same store
  28.     virtual IAStoreStream*    Clone() = 0;
  29.  
  30.     virtual bool    IsOpen() = 0;
  31.     virtual bool    IsWritable() = 0;
  32.     
  33.      IAMutex*            GetMutex() const {return mutex;}
  34. protected:
  35.     // ** Implementations of the following should lock the mutex while executing **
  36.  
  37.     // creates a new store
  38.     virtual void    Initialize() = 0;
  39.     // opens an existing store, enabling changes when 'writable' is true
  40.     virtual void    Open(bool writeable) = 0;
  41.  
  42.     // flushes buffered output to disk
  43.     virtual void    Flush() = 0;
  44.  
  45.     // returns one greater than the last position currently occupied
  46.     virtual uint32    GetEOF() = 0;
  47.     // truncates or extends the storage to the requested length
  48.     virtual void    SetEOF(uint32 address) = 0;
  49.  
  50.     // ** Remaining are only called with the mutex already locked. **
  51.  
  52.     virtual void    Write(uint32 address, const byte* data, uint32 length) = 0;
  53.     virtual uint32    Read(uint32 address, byte* data,  uint32 length) = 0;
  54.     
  55.     // Should be called by Flush() implementations.
  56.     void            MaybeFlushBuffer();    // write buffer if it's dirty & mark it clean
  57. private:
  58.     /// ** The following are only used by our friends, IAOutputBlock, IAInputBlock & IAStorage.
  59.  
  60.     // returns the position where the next read or write will happen
  61.     uint32            GetPosition() { return bufferPos + (nextByte - buffer); }
  62.     // sets the position where the next read or write will happen
  63.     // when writable, this will silently extend the file past EOF
  64.     // blockSize sets the limit for reading or writing
  65.     void            SetPosition(uint32 address, uint32 blockSize);
  66.  
  67.     // i/o primitives
  68.     // each increments the position by the number of bytes read or written
  69.     // reads may not be alternated with writes without an intervening call reposition
  70.     void            WriteByte(byte b) {
  71.                         if (nextByte < endByte) {
  72.                           *(nextByte++) = b;
  73.                         } else WritePastEndOfBuffer(b);
  74.                     }
  75.     byte            ReadByte() {
  76.                         return nextByte < endByte ? *(nextByte++) : ReadPastEndOfBuffer();
  77.                     }
  78.     void            WriteUInt32(uint32 i);
  79.     uint32            ReadUInt32();
  80.     void            WriteBytes(const void* b, uint32 l);
  81.     void            ReadBytes(void* b,  uint32 l);
  82.  
  83.     // really private stuff
  84.     byte*            buffer;                // the buffer
  85.     byte*            nextByte;            // pointer to the next character to read in buffer
  86.     byte*            endByte;            // pointer to the end of the buffer
  87.     uint32            bufferSize;            // amount to read/write     
  88.     uint32            bufferPos;            // position of the first char in buffer
  89.     uint32            blockEnd;            // don't permit read/writes past this     
  90.     bool            bufferDirty;
  91.  
  92.     byte            ReadPastEndOfBuffer();
  93.     void            WritePastEndOfBuffer(byte b);
  94.     IAMutex*        mutex;
  95.  
  96.                     IAStoreStream(IAStoreStream&);        // don't define a copy constructor
  97. };
  98.  
  99. IAExceptionCode            StoreError = 'VSEr';
  100. IAExceptionCode            StoreFull = 'VSFu';
  101. IAExceptionCode            StorePastBlockEnd = 'VSPB';
  102. IAExceptionCode            StorePastEOF = 'VSEo';
  103.  
  104. #pragma IA_END_EXPORTS
  105.  
  106. #pragma import reset
  107.  
  108. #endif
  109.